home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1993-94, Silicon Graphics, Inc.
- *
- * Permission to use, copy, modify, distribute, and sell this software and
- * its documentation for any purpose is hereby granted without fee, provided
- * that the name of Silicon Graphics may not be used in any advertising or
- * publicity relating to the software without the specific, prior written
- * permission of Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
- * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
- * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
- * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE
- * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
- */
- /*----------------------------------------------------------------------------
- *
- * otext.c : openGL (motif) demo to draw bitmapped fonts using display lists
- *
- * Author : Yusuf Attarwala
- * SGI - Applications
- *
- * Date : Feb 93
- *
- *---------------------------------------------------------------------------*/
- #include <stdio.h>
- #include <stdlib.h>
-
- #include <Xm/Xm.h>
- #include <Xm/Frame.h> /* for frame widgets */
-
- #include <GL/gl.h> /* gl includes */
- #include <GL/glu.h> /* utility library includes */
- #include <GL/GLwMDrawA.h> /* include for the drawing area widget */
-
- /* function declarations */
-
- int
- main(int,char **);
- static void
- createToplevel(void),
- drawScene(void),
- setMatrix(void),
- exposeCB(Widget, XtPointer, XtPointer),
- resizeCB(Widget, XtPointer, XtPointer),
- initCB(Widget, XtPointer, XtPointer);
-
- void makeFontSet(void),
- myCharStr(char *);
-
-
- /* global variables */
-
- Display *display; /* current display */
- XtAppContext appContext; /* X application context */
- GLuint base;
-
- Widget toplevel, /* toplevel shell */
- glw; /* current widget */
-
- GLXContext glxc; /* current glx context */
-
- char outputText[125];
- static GLfloat yellow[3] = {1.0,1.0,0.0};
-
- Arg args[20];
- int acnt;
-
- int
- main(int argc, char** argv)
- {
- int i;
- char oneWord[60];
-
- /* parse arguments, etc */
- if (argc > 1) {
- outputText[0] = '\0';
- for (i=1;i<argc;i++) {
- sprintf(oneWord,"%s ",argv[i]);
- strcat(outputText,oneWord);
- }
- }
- else {
- fprintf(stderr,"Usage : %s string1 [string2...]\n",argv[0]);
- strcpy(outputText,"HELLO WORLD");
- }
-
- XtToolkitInitialize();
- appContext = XtCreateApplicationContext();
- display = XtOpenDisplay(appContext, NULL, "Otext","otext",NULL,0,
- &argc,argv);
- if (!display) {
- printf("%s : Unable to open display\n",argv[0]);
- exit(0);
- }
- createToplevel(); /* create and realize widget hierarchy */
- XtAppMainLoop(appContext); /* loop for ever */
- }
-
-
-
- void
- createToplevel(void)
- {
- Widget frame;
-
- acnt = 0;
- XtSetArg(args[acnt],XmNminHeight, 200);acnt++;
- XtSetArg(args[acnt],XmNminWidth, 300);acnt++;
- toplevel = XtAppCreateShell("openGL text","xtext",
- applicationShellWidgetClass,
- display,args,acnt);
-
- /* create a frame to hold the glx drawing area */
- frame = XtVaCreateManagedWidget("frame",
- xmFrameWidgetClass, toplevel,
- NULL);
-
- /* create and manage a single buffer widget, rgb mode */
- acnt = 0;
- XtSetArg(args[acnt], GLwNrgba, TRUE); acnt++;
- glw = GLwCreateMDrawingArea(frame, "glw", args, acnt);
- XtManageChild(glw);
-
- /* register callbacks */
- XtAddCallback(glw, GLwNginitCallback, initCB, NULL);
-
- /* realize widget hierarchy */
- XtRealizeWidget(toplevel);
-
- /* generate display lists for text bitmaps */
- makeFontSet();
-
- /* additional callbacks */
- XtAddCallback(glw, GLwNresizeCallback, resizeCB, NULL);
- XtAddCallback(glw, GLwNexposeCallback, exposeCB, NULL);
-
- }
-
- void
- drawScene(void)
- {
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3fv(yellow);
- glRasterPos2i(10,10);
- myCharStr(outputText);
- glFlush();
- }
-
- static void
- setMatrix(void)
- {
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0.0,100.0,0.0,100.0,-1.0,1.0); /* a simple ortho */
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity(); /* default view */
- }
-
- static void
- resizeCB(Widget w, XtPointer client_data, XtPointer call)
- {
- GLwDrawingAreaCallbackStruct *call_data;
- call_data = (GLwDrawingAreaCallbackStruct *) call;
-
- GLwDrawingAreaMakeCurrent(w, glxc);
- glViewport(0, 0, call_data->width, call_data->height);
- setMatrix();
- drawScene();
- }
-
- static void
- exposeCB(Widget w, XtPointer client_data, XtPointer call)
- {
- GLwDrawingAreaCallbackStruct *call_data;
- call_data = (GLwDrawingAreaCallbackStruct *) call;
-
- GLwDrawingAreaMakeCurrent(w, glxc);
- drawScene();
- }
-
- static void
- initCB(Widget w, XtPointer client_data, XtPointer call)
- {
- XVisualInfo *vi;
-
- XtSetArg(args[0], GLwNvisualInfo, &vi);
- XtGetValues(w, args, 1);
-
- glxc = glXCreateContext(XtDisplay(w), vi, 0, GL_TRUE);
- }
-
- void
- makeFontSet()
- {
- XFontStruct *xfont;
- unsigned int firstChar, lastChar;
-
- GLwDrawingAreaMakeCurrent(glw, glxc);
-
- xfont = XLoadQueryFont(display,"9x15");
- /* replace 9x15 with your favorite font set */
-
- if (!xfont) {
- fprintf(stderr,"FONT NOT FOUND \n");
- exit(0);
- }
-
- firstChar = xfont->min_char_or_byte2;
- lastChar = xfont->max_char_or_byte2;
-
- if (base = glGenLists(lastChar-firstChar+1)) {
- glXUseXFont(xfont->fid,firstChar,lastChar-firstChar+1,base+firstChar);
- }
- else {
- fprintf(stderr,"OUT OF DISPLAY LISTS\n");
- exit(0);
- }
- }
-
- void
- myCharStr(char *s)
- {
- glPushAttrib(GL_LIST_BIT);
- glListBase(base);
- glCallLists(strlen(s),GL_UNSIGNED_BYTE,(unsigned char *)s);
- glPopAttrib();
- }
-
-